package www.notice;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


import www.member.sqlmap.GetSqlMapClient;

import com.ibatis.sqlmap.client.SqlMapClient;

public class NoticeDAO implements INoticeDAO {

    private SqlMapClient sqlMapClient;

    public NoticeDAO() {
        super();
        sqlMapClient = GetSqlMapClient.get();
    }

    @Override
    public Object create(Object dto)
            throws SQLException {
        System.out.println("Notice >> Create ");
        
        NoticeDTO member_dto = (NoticeDTO) dto;
        Map map = new HashMap();
        
        map.put("i_noticeno", member_dto.getNoticeno());
        map.put("i_nickname", member_dto.getNickname());
        map.put("i_title", member_dto.getTitle());
        map.put("i_contents", member_dto.getContents());
        map.put("i_profilephoto", member_dto.getProfilephoto());
        map.put("i_noticedate", member_dto.getNoticedate());
        Object obj = null;
        obj = sqlMapClient.insert("notice.create", map);
        int retVal = (Integer)map.get("o_cnt");
        return retVal;
    }

    @Override
    public Object delete(Object noticeno) throws SQLException {
        System.out.println("Notice >> Delete ");
        
        //MemberDTO member_dto = (MemberDTO) dto;
        Map map = new HashMap();
        
        map.put("i_noticeno", noticeno);
        Object obj = null;
        obj = sqlMapClient.delete("notice.delete", map);
        System.out.println("readobj: "+obj);
        int retVal = (Integer)map.get("o_cnt");
        return retVal;
    }

    @Override
    public Object update(Object dto) throws SQLException {
        System.out.println("Notice >> UPdate ");
        
        NoticeDTO member_dto = (NoticeDTO) dto;
        Map map = new HashMap();
        
        map.put("i_noticeno", member_dto.getNoticeno());
        map.put("i_nickname", member_dto.getNickname());
        map.put("i_title", member_dto.getTitle());
        map.put("i_contents", member_dto.getContents());
        map.put("i_profilephoto", member_dto.getProfilephoto());
        map.put("i_noticedate", member_dto.getNoticedate());
        Object obj = null;
        obj = sqlMapClient.insert("notice.update", map);
        int retVal = (Integer)map.get("o_cnt");
        return retVal;
    }

    
    @Override
//    public ArrayList<Object> list(Map map) throws SQLException{
//        System.out.println("out - map: " + map.hashCode());
//        ArrayList<Object> list = null;
//
//        list = (ArrayList<Object>)sqlMapClient.queryForList("member.list_member", map);
//
//        return list;
//    }
        public ArrayList<Object> list() throws SQLException {
        ArrayList<Object> list = null;
        list = (ArrayList<Object>) sqlMapClient
                .queryForList("notice.list_notice");
        return list;
    }

    
    
    @Override
    public Object read(Object pk) throws SQLException{
        Object obj = null;
        obj = sqlMapClient.queryForObject("notice.read_notice", pk);
        System.out.println("readobj: "+obj);
        return obj;
    }

    


}
